home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
gray image 2.1
/
window.h
< prev
next >
Wrap
Text File
|
1995-06-11
|
3KB
|
106 lines
/*
***********************************************************************
*
*
* Simple Window Class
*
*
***********************************************************************
*/
/*
*----------------------------------------------------------------------
* Service functions
*/
class IMAGE; // Opaque class
class ScreenRect : public Rect
{
public:
ScreenRect(const Rect& rect) : Rect(rect) {}
ScreenRect(const IMAGE& image);
ScreenRect(const rowcol& heightwidth);
// Create a rectangle of given height/width
// positioned at a given point
ScreenRect(const rowcol& origin, const rowcol& heightwidth);
ScreenRect& operator += (const int offset);
operator Rect * (void) { return this; }
void print(const char * title = "") const;
};
/*
*----------------------------------------------------------------------
* A generic simple window that can be dragged around the screen
* and closed by clicking a "go-away" button
* No other events are handled, redefine the event handler if necessary.
*/
class ScreenWindow
{
WindowPtr this_window;
Boolean handle_mouse_down(const EventRecord& the_event);
virtual Boolean handle_key_down(const EventRecord& the_event); // Handles key_down & auto_key events
virtual Boolean handle_null_event(const long event_time);
void drag(Point where) { DragWindow(this_window,where,&qd.screenBits.bounds); }
void activate(const Boolean go_active);
void update(void);
virtual void draw(void) = 0; // It is this function that really draws smth
protected:
WindowPtr our_window(void) const { return this_window; }
public:
ScreenWindow(ScreenRect rect, const char * title);
ScreenWindow(const short resource_id); // Create a window from a resource template
~ScreenWindow(void);
void handle(void);
void refresh(void);
};
/*
*----------------------------------------------------------------------
* A simple window with an offscreen window buffer
*/
class OffScreenWindow : public ScreenWindow
{
friend class SetOffscreenWorld;
GWorldPtr graf_world; // (Offscreen) graphical world that contains the picture
void activate_palette(void); // Activate palette for the window
void draw(void); // Draw the offscreen buffer on screen
protected:
PixMapHandle pixmap; // Pixmap for the offscreen world
int _height; // Dimensions of the pixmap (precomputed for
int _width; // easy reference
int _bytes_per_row; // Note, bytes_per_row >= width (and generally, not equal)
public:
OffScreenWindow(ScreenRect rect, const char * title, const short clut_id=0);
~OffScreenWindow(void);
PixMapHandle get_pixmap(void) const { return pixmap; }
ScreenRect q_bounds(void) const; // Bounding rect of the grafworld
int height(void) const { return _height; }
int width(void) const { return _width; }
int bytes_per_row(void) const { return _bytes_per_row; }
};
// Make it easy setting and resetting
// the current window
class SetOffscreenWorld
{
GrafPtr old_port;
public:
// Switch to an off-screen grafworld
SetOffscreenWorld(const OffScreenWindow& offscreen_window)
{ GetPort(&old_port); SetPort((GrafPtr)offscreen_window.graf_world); }
// Restore the original grafworld
~SetOffscreenWorld(void) { SetPort(old_port); }
};